package xyz.xuminghai.javafx_learn.scene.control;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Accordion;
import javafx.scene.control.Button;
import javafx.scene.control.TitledPane;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

/**
 * 2023/1/16 9:43 星期一<br/>
 * 手风琴是一组TitlePanes 。一次只能打开一个 TitledPane。
 * 手风琴中的TitledPane内容可以是任何Node ，例如 UI 控件或添加到布局容器的节点组。
 *
 * @author xuMingHai
 */
public class AccordionApp extends Application {

    private final AnchorPane anchorPane = new AnchorPane();

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void init() {
        // 添加控件
        TitledPane titledPane1 = new TitledPane("titledPane1", new Button("button1"));
        TitledPane titledPane2 = new TitledPane("titledPane2", new Button("button2"));
        TitledPane titledPane3 = new TitledPane("titledPane3", new Button("button3"));
        Accordion accordion = new Accordion(titledPane1, titledPane2, titledPane3);

        accordion.expandedPaneProperty().addListener((observable, oldValue, newValue) -> {
            if (newValue != null) {
                System.out.println(newValue.getText());
            }
        });


        anchorPane.getChildren().add(accordion);
        AnchorPane.setTopAnchor(accordion, 100.0);
        AnchorPane.setLeftAnchor(accordion, 100.0);
    }

    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle(getClass().getSimpleName());
        primaryStage.setScene(new Scene(anchorPane, 800, 600));
        primaryStage.show();
    }
}
